//
// Created by EDZ on 2020/2/14.
//

#ifndef PUSHER_VIDEOCHANNEL_H
#define PUSHER_VIDEOCHANNEL_H

#include <pthread.h>
#include <x264.h>
#include <cstdint>
#include <string.h>
#include <rtmp.h>
#include "macro.h"

class VideoChannel {
    typedef void(*VideoCallback)(RTMPPacket *packet);

public:
    VideoChannel();

    virtual ~VideoChannel();

    void initVideoEncoder(int width, int height, int bitrate, int fps);

    void encodeData(int8_t *data);

    void setVideoCallback(VideoCallback callback);

private:
    int mWidth;
    int mHeight;
    int mBitrate;
    int mFps;
    pthread_mutex_t mutex;
    x264_t *videoEncoder = 0;
    x264_picture_t *pic_in = 0;
    int y_len;
    int uv_len;
    VideoCallback videoCallback;

    void sendSpsPps(uint8_t *sps, uint8_t *pps, int spsLen, int ppsLen);

    void sendFrame(int type, uint8_t *payload, int iPayload);
};


#endif //PUSHER_VIDEOCHANNEL_H
